#pragma once

#include <vector>
#include <map>

#include "HybridSRStrategy.h"
#include "SpeechRecognizer.h"
#include "HybridSRContext.h"

#include "UILogger.h"
#include "UIConfigResourceManager.h"

class HybridSpeechRecognizer
{
public:
	HybridSpeechRecognizer();
	~HybridSpeechRecognizer(void);

	inline bool isInitialized(void)	{ return m_isInit; }
	
	void updateContext(std::string key, std::string value);

	bool recFromMic(long sessionID, std::string logAudioFileName);
	bool recFromFile(long sessionID, const char* file);
	bool test(SRNLUReference reference);
	bool stopRecording(long sessionID);
	bool cancel(void);

	static void endRecording(int sessionID);
	static void fireSRError(int sessionID, SRError error);

private:
	bool initialize(void);
	bool parseStrategy(std::string filename);

	bool parseStrategySection(std::string content, HybridSRStrategy* strategy);
	bool parseConditionSection(std::string content, HybridSRStrategy* strategy);
	bool parseEngineSection(std::string content, HybridSRStrategy* strategy);
	bool parseSyncSection(std::string content, HybridSRStrategy* strategy);
	bool parsePostProcessSection(std::string content, HybridSRStrategy* strategy);

	bool m_isInit;

	HybridSRContext					m_context;

	HybridSRStrategy				m_defaultStrategy;
	HybridSRStrategy				m_currentStrategy;
	std::vector<HybridSRStrategy>	m_strategies;

	std::vector<SpeechRecognizer*>	m_engines;
	std::map<SREngineType, SpeechRecognizer*> m_EngineType2Engine;

	SREngineType					m_recordEngineType;
	SpeechRecognizer*				m_recordEngine;
	
	UILogger*						m_pLogger;
	UIConfigResourceManager*		m_pConfigurator;
};

